package org.whh.beans.factory.support;

import lombok.extern.log4j.Log4j2;
import org.whh.beans.factory.config.BeanDefinition;
import org.whh.common.exception.BeansException;

@Log4j2
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{
    @Override
    protected Object createBean(String name, BeanDefinition beanDefinition) throws BeansException {
        Object bean;

        try {
            bean = beanDefinition.getClazz().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            log.error("创建bean失败",e);
            throw new BeansException("创建bean失败",e);
        }
        addSingleton(name,bean);

        return bean;
    }
}
